package com.glodon.paas.document.storage.util;

import java.io.IOException;
import java.io.OutputStream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.MapperWrapper;

@SuppressWarnings({ "rawtypes" })
public class OssUtil {

    public static void toXml(Object bean, OutputStream out) {
        try {
            XStream xstream = new XStream() {
                @Override
                protected MapperWrapper wrapMapper(MapperWrapper next) {
                    return new MapperWrapper(next) {
                        @Override
                        public String serializedClass(Class type) {
                            return type.getSimpleName();
                        }

                        @Override
                        public String serializedMember(Class type, String memberName) {
                            return memberName.substring(0, 1).toUpperCase() + memberName.substring(1);
                        }
                    };
                }
            };
            out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes());
            xstream.toXML(bean, out);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
